Nginx安装免费https证书(Let‘s Encrypt)申请与配置(一) |
您所在的位置:网站首页 › letsencrypt证书申请 80端口不能访问 › Nginx安装免费https证书(Let‘s Encrypt)申请与配置(一) |
Let's Encrypt —— 是一个由非营利性组织 互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构(CA),简单的说,就是为网站提供免费的 SSL/TLS 证书。 Let's Encrypt 生成证书的工具很多,certbot 是官方推荐的签发工具,操作起来比较简单,由于我们的网站经常会使用Apache或者Nginx进行代理,本次在操作系统Centos8以Certbot生成Nginx证书为例进行配置,官网如下: Certbot官网,针对每类web服务和操作系统都有对应的操作手册 一、前提1,Certbot支持的Web服务才可以使用Certbot自动生成并安装证书;虽然支持Nginx,但是基于Nginx的OpenResty并不支持,期待后期Certbot能够支持OpenResty; 2,需要事先安装好Nginx,并指定Nginx的环境变量PATH vim /etc/bashrc export PATH=/usr/local/nginx/sbin:$PATH source /etc/bashrc3,certbot找nginx进程是通过nginx.pid文件查找,默认从nginx的安装目录/usr/local/nginx/logs/nginx.pid查找,找不到会报错。 4,事先得有域名,可以是免费域名,根据项目提前申请准备好; 5,域名需要解析到指定的服务器,需要通过Internet能够访问到域名,即域名需要绑定对应的公网IP地址; 6,在Nginx服务的配置文件nginx.conf需要指定认证的域名对应server_name,如 server_name xunlu.aits-lrn.com tpu.aits-lrn.com; 7,关闭Selinux,否则会在执行过程中报错:error: too early for operation, device not yet seeded or device model not acknowledged; 不重启的头闭# setenforce 0 #当前有效,重启电脑后失效 重启电脑的关闭# vi /etc/selinux/config把SELINUX=enforce 改成disabled就可以了,重启电脑,永久生效 二、证书生成证书生成有两种方式 1,自动生成,通过Certbot官网提供的文档 Nginx on CentOS 8 本次选择Nginx服务Centos8操作系统 2,手动生成,通过手动执行Certbot证书生成命令来完成 本次以自动生成方式进行演示。 三、证书安装过程要使用Certbot,需要安装snapd,这个工具是Certbot必须依赖的,事先需要在你的Nginx服务对应的操作系统执行安装snapd。 1,安装snapd官网提供了安装文档,按照此方式执行,具体步骤如下 Installing snap on CentOS 1.1 安装EPEL库 sudo dnf install epel-release sudo dnf upgrade1.2 snapd安装 sudo yum install snapd sudo systemctl enable --now snapd.socket sudo ln -s /var/lib/snapd/snap /snap2,移除原有Certbot-auto的安装包 sudo yum remove certbot3,安装Certbot sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot4,运行Certbot 4.1 自动运行并完成证书安装配置 sudo certbot --nginx首次执行会报错 [root@master01 ~]# sudo certbot --nginx Saving debug log to /var/log/letsencrypt/letsencrypt.log The nginx plugin is not working; there may be problems with your existing configuration. The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)上面提示信息显示没有找到nginx,那么需要将nginx放到环境变量中,设置nginx软连接 ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx ln -s /usr/local/nginx/conf/ /etc/nginx再执行sudo certbot --nginx就可以正常执行。 4.2 仅生成证书后手动配置 sudo certbot certonly --nginx5,自动更新证书 为了证书不被过期,需要定期更新证书有效期,可以执行命令 sudo certbot renew --dry-run此命令会自动创建一个job执行,在证书过期之前自动更新有效期,job位置在其中以下一个位置: /etc/crontab//etc/cron.*/*systemctl list-timers6,当需要安装新的证书 sudo certbot run --nginx7,验证证书安装结果 在浏览器访问 https://yourwebsite.com/ 参考资料 【Nginx】使用certbot安装免费https证书使Nginx支持Https请求 Configuring certbot-nginx for OpenResty 免费 https 证书(Let's Encrypt)申请与配置1 免费 https 证书(Let's Encrypt)申请与配置2 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |